import requests
from lxml import etree
import urllib.request
from chaojiying import Chaojiying_Client
if __name__ == '__main__':
    dl = "https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3877.400 QQBrowser/10.8.4506.400"
    }

    session = requests.session()
    yzm_img = requests.get(url=dl, headers=headers)
    contentimg = yzm_img.text
    print(contentimg)
    tree = etree.HTML(contentimg)
    vi1 = tree.xpath("//form/div[1]/input/@value")[0]
    vi2 = tree.xpath("//form/div[2]/input/@value")[0]
    yzm_src = tree.xpath("//form/div[4]/div[4]/img/@src")[0]

    img_url = "https://so.gushiwen.cn" + yzm_src

    img_content = session.get(img_url)

    content_code = img_content.content
    with open("ym.jpg", "wb") as fs:
        fs.write(content_code)
    # urllib.request.urlretrieve(url=img_url, filename="a.jpg")
    ying=Chaojiying_Client()
    ying_yzm=ying.yydss()

    # yan = input("请输入验证码:")
    yan=ying_yzm

    data = {
        "__VIEWSTATE": vi1,
        "__VIEWSTATEGENERATOR": vi2,
        "from": "http://so.gushiwen.cn/user/collect.aspx",
        "email": "2817898894@qq.com",
        "pwd": "zyj141247830",
        "code": yan,
        "denglu": "登录",
    }

    response = session.post(url=dl, headers=headers, data=data)
    contenth = response.text
    with open("as.html", "w", encoding="utf-8") as f:
        f.write(contenth)

    # d=Chaojiying_Client("A")
    # d.maina()
    # print(d.rrrr)

#	924062	状态:0
#   软件说明:软件KEY:f62457ac3267103a4de89eb1f9cd80b5
